package com.buaa.airticketbookingsystem.Service.UserServiceImpl;

import com.buaa.airticketbookingsystem.Dao.PurchaseRecordDao;
import com.buaa.airticketbookingsystem.Dao.TicketDao;
import com.buaa.airticketbookingsystem.Dao.UserDao;
import com.buaa.airticketbookingsystem.Entity.PurchaseRecord;
import com.buaa.airticketbookingsystem.Service.PurchaseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PurchaseRecordServiceImpl implements PurchaseRecordService {

    @Autowired
    private PurchaseRecordDao purchaseRecordDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private TicketDao ticketDao;

    @Override
    public void addNewPurchaseRecord(PurchaseRecord purchaseRecord) {
        purchaseRecordDao.addNewPurchaseRecord(purchaseRecord);
        purchaseRecordDao.setTicketPurchased(purchaseRecord.getT_id());
    }

    @Override
    public void deletePurchaseRecordByIdAndEmail(String no, String t_id) {
        purchaseRecordDao.delPR(no);
        ticketDao.add(t_id);
    }

    @Override
    public List<PurchaseRecord> getAllPurchaseRecordByUser(String email) {
        return purchaseRecordDao.getAllPurchaseRecordByUser(email);
    }

    @Override
    public PurchaseRecord getPurchaseRecordByAll(String email, String t_id){
        return purchaseRecordDao.getPurchaseRecordByAll(email, t_id);
    }

    @Override
    public PurchaseRecord getPurchaseRecordByNo(String no){
        return purchaseRecordDao.getPurchaseRecordByNo(no);
    }

    @Override
    public void payPurchaseRecord(String no, String email, double money){
        purchaseRecordDao.payPurchaseRecord(no);
        userDao.pay(email, money);
    }

    @Override
    public void refund(String no){
        purchaseRecordDao.refund(no);
    }

    @Override
    public void delPR(String no){
        purchaseRecordDao.delPR(no);
    }

}
